<template>
  <div>
    <el-form :inline="true" label-width="80px">
      <el-form-item label="手机号码">
        <el-input
          v-model="queryParams.mobile"
          placeholder="手机号码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="昵称/姓名">
        <el-input
          v-model="queryParams.nickname"
          placeholder="昵称/姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="角色">
        <el-select v-model="queryParams.role" placeholder="角色" clearable size="small">
          <el-option
            v-for="dict in roleOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="状态">
        <el-select v-model="queryParams.status" placeholder="状态" clearable size="small">
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="邀请时间">
        <el-date-picker
          v-model="startTime"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="40" class="panel-group">
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-people">
            <svg-icon icon-class="peoples" class-name="card-panel-icon"/>
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              一级创客人数
            </div>
            <count-to :start-val="0" :end-val="level1" :duration="2600" class="card-panel-num">{{ level1 }} 人</count-to>
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-people">
            <svg-icon icon-class="peoples" class-name="card-panel-icon"/>
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              二级创客人数
            </div>
            <count-to :start-val="0" :end-val="level2" :duration="2600" class="card-panel-num">{{level2}}</count-to>
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel">
          <div class="card-panel-icon-wrapper icon-people">
            <svg-icon icon-class="peoples" class-name="card-panel-icon"/>
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              总共创客人数
            </div>
            <count-to :start-val="0" :end-val="(level2+level1)" :duration="2600" class="card-panel-num">{{ level2+level1
              }} 元
            </count-to>
          </div>
        </div>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="postList"
              row-key="userId"
              :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
      <el-table-column label="用户编号" align="center" prop="idNo"/>
      <el-table-column label="头像" align="center" prop="avatar">
        <template slot-scope="scope">
          <div>
            <el-popover placement="right" title="" trigger="click">
              <img :src="scope.row.avatar" alt="">
              <img slot="reference" :src="scope.row.avatar" alt="" style="max-height: 50px;max-width: 50px">
            </el-popover>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="昵称" align="center" prop="nickname"/>
      <el-table-column label="手机号码" align="center" prop="mobile"/>
      <el-table-column label="性别" align="center" prop="gender" :formatter="genderFormat"/>
      <el-table-column label="真实姓名" align="center">
        <template slot-scope="scope">
          <span :class="scope.row.realName?'':'text-warning'">{{ scope.row.realName?scope.row.realName:'未实名' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="角色" align="center" prop="role" :formatter="roleFormat"/>

      <el-table-column label="状态" align="center" prop="status" :formatter="statusFormat"/>

      <el-table-column label="邀请时间" align="center" prop="createtime" width="180">
        <template slot-scope="scope">
          <span>{{ dateFormat(scope.row.createtime) }}</span>
        </template>
      </el-table-column>

      <el-table-column label="是否创客" align="center">
        <template slot-scope="scope">
          <span :class="scope.row.makerId?'text-success':'text-warning'">{{ scope.row.makerId?'是':'否' }}</span>
        </template>
      </el-table-column>

    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
  import {inviteList} from "@/api/maker/list";
  import CountTo from 'vue-count-to';

  export default {
    props: {
      row: {
        type: Object,
        require: true
      }
    },
    components: {
      CountTo
    },
    data() {
      return {
        startTime: '',
        // 遮罩层
        loading: true,
        // 总条数
        total: 0,
        // 岗位表格数据
        postList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 状态数据字典
        statusOptions: [],
        roleOptions: [],
        genderOptions: [],
        max: 99999,
        content: '',
        level1: 0,
        level2: 0,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          mobile: undefined,
          nickname: undefined,
          status: undefined,
          startTime: undefined,
          endTime: undefined,
          role: undefined,
        },
        rules: {}
      };
    },
    created() {
     // this.content = '用户昵称为:' + this.$route.params.nickname + ",手机号为:" + this.$route.params.mobile + "的下级记录";
      this.getDicts("yy_user_status").then(response => {
        this.statusOptions = response.data;
      });
      this.getDicts("sys_user_sex").then(response => {
        this.genderOptions = response.data;
      });
      this.getDicts("yy_user_role").then(response => {
        this.roleOptions = response.data;
      });
      console.log(this.row);
      this.queryParams.userId =this.row.userId;
      this.getList();
    },
    methods: {
      getList() {
        this.loading = true;
        inviteList(this.queryParams).then(response => {
          console.log(response);
          this.postList = response.list.rows;
          this.total = response.list.total;
          this.level1 = response.level1;
          this.level2 = response.level2;
          this.loading = false;
        });
      },
      statusFormat(row, column) {
        return this.selectDictLabel(this.statusOptions, row.status);
      },
      roleFormat(row, column) {
        return this.selectDictLabel(this.roleOptions, row.role);
      },
      genderFormat(row, column) {
        return this.selectDictLabel(this.genderOptions, row.gender);
      },
      handleQuery() {
        if (this.startTime) {
          this.queryParams.startTime = this.startTime[0] + " 00:00:00";
          this.queryParams.endTime = this.startTime[1] + " 23:59:59";
        } else {
          this.queryParams.startTime = null;
          this.queryParams.endTime = null;
        }
        this.queryParams.pageNum = 1;
        this.getList();
      }
    }
  };
</script>

<style lang="scss" scoped>
  .panel-group {
    margin-top: 18px;

    .card-panel-col {
      margin-bottom: 32px;
    }

    .card-panel {
      height: 108px;
      cursor: pointer;
      font-size: 12px;
      position: relative;
      overflow: hidden;
      color: #666;
      background: #fff;
      box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
      border-color: rgba(0, 0, 0, .05);

      &:hover {
        .card-panel-icon-wrapper {
          color: #fff;
        }

        .icon-people {
          background: #40c9c6;
        }

        .icon-message {
          background: #36a3f7;
        }

        .icon-money {
          background: #f4516c;
        }

        .icon-shopping {
          background: #34bfa3
        }
      }

      .icon-people {
        color: #40c9c6;
      }

      .icon-message {
        color: #36a3f7;
      }

      .icon-money {
        color: #f4516c;
      }

      .icon-shopping {
        color: #34bfa3
      }

      .card-panel-icon-wrapper {
        float: left;
        margin: 14px 0 0 14px;
        padding: 16px;
        transition: all 0.38s ease-out;
        border-radius: 6px;
      }

      .card-panel-icon {
        float: left;
        font-size: 48px;
      }

      .card-panel-description {
        float: right;
        font-weight: bold;
        margin: 26px;
        margin-left: 0px;

        .card-panel-text {
          line-height: 18px;
          color: rgba(0, 0, 0, 0.45);
          font-size: 16px;
          margin-bottom: 12px;
        }

        .card-panel-num {
          font-size: 20px;
        }
      }
    }
  }

  @media (max-width: 550px) {
    .card-panel-description {
      display: none;
    }

    .card-panel-icon-wrapper {
      float: none !important;
      width: 100%;
      height: 100%;
      margin: 0 !important;

      .svg-icon {
        display: block;
        margin: 14px auto !important;
        float: none !important;
      }
    }
  }
</style>
